package com.zzyl.controller.customer;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.dto.VisitDto;
import com.zzyl.service.customer.ReservationService;
import com.zzyl.utils.UserThreadLocal;
import com.zzyl.vo.TimeCountVo;
import com.zzyl.vo.VisitVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description CustomerReservationController
 * @Author liangDong
 * @Date 2025-05-16  12:04
 */
@RestController
@RequestMapping("/customer/reservation")
public class CustomerReservationController extends BaseController {
    @Autowired
    private ReservationService reservationService;

    @GetMapping("/cancelled-count")
    public ResponseResult getCancelledCount(){

        //Integer count = reservationService.getCancelledCount();
        //return success(count);

        //测试拦截器
        Integer count = reservationService.getCancelledCount();
        return success(count);
    }

    @GetMapping("/countByTime")
    public ResponseResult countByTime(Long time){
        List<TimeCountVo> countList = reservationService.getCountList(time);
        return success(countList);
    }

    @PostMapping
    public ResponseResult addReservation(@RequestBody VisitDto visitDto){
        reservationService.add(visitDto);
        return success();
    }

    @GetMapping("/page")
    public ResponseResult<PageResponse<VisitVo>> page(
            @RequestParam(value = "status", required = false)  String status,
            @RequestParam(value = "pageNum", defaultValue = "1")  int pageNum,
            @RequestParam(value = "pageSize", defaultValue = "10")  int pageSize
    ){
        int status1 = 0;
        if (status=="") {
        }else {
             status1 = Integer.valueOf(status);
        }

        PageResponse<VisitVo> visitList = reservationService.page(status1,pageNum,pageSize);
        return success(visitList);
    }


    @PutMapping("/{id}/cancel")
    public ResponseResult cancelReservation(@PathVariable Long id){
        reservationService.cancel(id);
        return success();
    }

}
